import axios from "axios";
import { String } from "core-js";

//配置axios基准路径
axios.defaults.baseURL = 'http://ludir.cn:8888/api/private/v1/'

//添加请求拦截器
axios.interceptors.request.use(function (config) {
    //发送请求前携带token
    let resData = JSON.parse(localStorage.getItem('userName')) || []

    config.headers['Authorization'] = resData.token
    return config
},function (error) {
    //对错误请求的处理
    return Promise.reject(error)
})

//添加响应拦截器
axios.interceptors.response.use(function (response){
    //对响应码200以内的响应数据做处理
    return response.data
},function (error){
    //对响应码超过200的响应数据做处理
    return Promise.reject(error)
})

 //登录验证
 export const checkLogin = params => axios.post('login', params)

//获取用户列表
export const getUserList = params => axios.get('users', params)

//修改用户状态
export const changeUserState = params => axios.put(`users/${params.uid}/state/${params.type}`,params)

// 左侧菜单权限列表
export const getMenus = params => axios.get('menus',{ params })

//添加用户
export const addUser = params => axios.post('users',params)

//删除用户
export const deleteUser = params => axios.delete(`users/${params}`)

//根据id获取用户信息
export const getUserById = params => axios.get(`users/${params}`)

//编辑用户信息
export const editUser = params => axios.put(`users/${params.id}`,params)

//获取角色列表
export const getRoleList = params => axios.get('roles')

//分配角色
export const disUserRole = params => axios.put(`users/${params.id}/role`,{id:params.id,rid:params.rid})

//获取权限列表
export const getRightList = params => axios.get(`rights/${params.type}`)

//添加角色
export const addRole = params => axios.post('roles',params)

//删除角色
export const deleteRole = params => axios.delete(`roles/${params}`)

//通过id获取角色信息
export const getRoleById = params => axios.get(`roles/${params}`)

//编辑角色
export const editRole = params => axios.put(`roles/${params.roleId}`,params)

//删除角色权限
export const deleteRoleRight = params => axios.delete(`roles/${params.roleId}/rights/${params.rightId}`)

//提交角色授权
export const grandRoleRight = params => axios.post(`roles/${params.roleId}/rights`,{rids:params.rids})

//商品分类数据获取
export const getCategories = params => axios.get('categories',{params})

//添加商品分类 
export const addCategories = params => axios.post('categories',params)

//获取订单列表
export const getOlders = params => axios.get('orders',params)

//通过id查看订单详细
export const getOldersById = params => axios.get(`orders/${params}`)

//编辑订单
export const editOrders = params => axios.put(`orders/${params.id}`,params)

//获取物流
export const getPostMan = params => axios.get(`kuaidi/${params.id}`)

//数据可视化
export const getCharts = params => axios.get(`reports/type/1`)

//获取商品列表
export const getGoods = params => axios.get("goods",params)

//通过id获取商品
export const getGoodsById = params => axios.get(`goods/${params}`)

//删除商品
export const deleteGoods = params => axios.delete(`goods/${params}`)

//获取商品分类
export const getCateList = params => axios.get("categories",params)

//添加商品
export const addGoods = params => axios.post("goods",params)

//获取分类参数
export const getParams = params => axios.get(`categories/${params.id}/attributes`,params)

//添加分类
export const addParams = params => axios.post(`categories/${params.id}/attributes`,params)

//通过id获取分类参数
export const getParamsById = params => axios.get(`categories/${params.id}/attributes/${params.attrId}`,params)

//编辑分类参数
export const editParams = params => axios.put(`categories/${params.id}/attributes/${params.attrId}`,params)

//删除分类
export const deleteParams = params => axios.delete(`categories/${params.id}/attributes/${params.attrId}`)

//添加商品分类
export const addShop = params => axios.post(`categories`,params)

//通过id获取商品分类
export const getShopById = params => axios.get(`categories/${params.id}`)

//编辑商品分类
export const editShop = params => axios.put(`categories/${params.id}`,params)

//删除商品分类
export const deleteShop = params => axios.delete(`categories/${params.id}`)

